import java.io.BufferedReader;
import java.io.File;
import java.io.FileFilter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;


public class WordFileFilter implements FileFilter {

	private String word; 
	public WordFileFilter(String word){
		this.word = word;		
	}

	@Override
	public boolean accept(File file) {	
		return file.isFile() && answer(file);
	}
		
	private boolean answer(File file){
		boolean answer = false;
		String line; 
		try {
			BufferedReader bfr = new BufferedReader(new FileReader(file));
			while((line = bfr.readLine()) != null){
				if (line.toLowerCase().contains(word.toLowerCase())){
					answer = true;
					break;
				}
			}
			bfr.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		return answer; 
	}

}
